package org.shock.ss.sms.action.system;

import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import org.shock.ss.sms.service.system.ProjectLogService;
import org.shock.ss.sms.service.system.impl.ProjectLogServiceImpl;
import org.shock.ss.sms.bean.Page;
import org.shock.ss.sms.bean.Pager;
import org.shock.ss.sms.bean.system.ProjectLog;
import org.shock.ss.sms.commons.annotation.RightAnno;
import org.shock.ss.sms.commons.utils.Util;
import org.shock.ss.sms.commons.dao.DaoFactory;
import org.shock.ss.sms.dao.system.impl.ProjectLogDaoImpl;
import org.shock.ss.sms.action.BaseAction;

public class ProjectLogAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	ProjectLogService ps = new ProjectLogServiceImpl(
			(ProjectLogDaoImpl) DaoFactory.getDao("ProjectLogDao"));
	private List loglist;
	private ProjectLog bean = new ProjectLog();

	/**
	 * 分页显示日志日志列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@RightAnno(rightValue = "ProjectLogList", rightNote = "日志列表")
	public String ProjectLogList() throws Exception {
		StringBuffer sul = new StringBuffer("page=1");
		if (0 == pageno)
			pageno = 1;
		if (!Util.isEmpty(bean.getOpzh())) {
			sqladd.append(" and opzh like '%").append(
					Util.nulltoempty(bean.getOpzh())).append("%'");
			sul.append("&bean.dsmc=").append(bean.getOpzh());
		}
		if (!Util.isEmpty(bean.getType())) {
			sqladd.append(" and type like'%").append(
					Util.nulltoempty(bean.getType())).append("%'");
			sul.append("&bean.type =").append(bean.getType());
		}

		/** Pager bean 封装 list 和 总数 */
		Pager pager = new Pager(); 
		/** 分页的参数处理 */
		// String sul = ParamsUtil.transParams(getRequest().getParameterMap());
		sul.append("&pagecount=").append(pagecount);
		/** 获得总数语句 */
		String sqlcount = "select count(1) from "+ProjectLog.getTable()+" where 1=1 " + sqladd;
		/** 分页语句 */
		String sql = "select id,type,opzh,optime,opip,content,bgcontent from "+ProjectLog.getTable()+" where 1=1"
				+ sqladd;
		System.out.println(sql+"==");
		/** 获得pager */
		pager = ps.list("desc", "optime desc,id", pageno, rownum, sqlcount, sql);
		loglist = pager.getList();
		Page page = new Page();
		page.setPageString(pager.getTotalCount(), rownum, pageno, pagerow, sul
				.toString());
		pageStr = page.getPageString();
		return SUCCESS;
	}

	@RightAnno(rightValue = "lookLog", rightNote = "日志查看")
	public String lookLog() throws Exception {
		String sql = "select id,type,opzh,optime,opip,content,bgcontent from "+ProjectLog.getTable()+" where id ="
				+ bean.getId();
		Map map = ps.view(sql);
		BeanUtils.populate(bean, map);
		return SUCCESS;
	}
	@RightAnno(rightValue = "deleteLog", rightNote = "删除日志")
	public String deleteLog() throws Exception {
		String sql = "delete from "+ProjectLog.getTable()+" where id =" + bean.getId();
		ps.del(sql);
		return SUCCESS;
	}


	public List getLoglist() {
		return loglist;
	}

	public void setLoglist(List loglist) {
		this.loglist = loglist;
	}

	public ProjectLog getBean() {
		return bean;
	}

	public void setBean(ProjectLog bean) {
		this.bean = bean;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
}
